package com.cgy.utils.jmx.jvm.mem;

import com.cgy.utils.jmx.IJvmInfoFactory;
import com.cgy.utils.jmx.jvm.utils.SizeUtils;

import static com.cgy.utils.jmx.RateHelper.rate;

/**
 * @author CHTK
 */
public class MemJvmFactory extends IJvmInfoFactory {

    private Runtime runtime = Runtime.getRuntime();

    @Override
    public void status() {
        long max = runtime.totalMemory();
        long free = runtime.freeMemory();
        long used = max - free;

        put("mem.jvm.total.long", max, "Jvm 最大内存");
        put("mem.jvm.total.String", SizeUtils.getDataSize(max), "Jvm 最大内存");

        put("mem.jvm.used.long", used, "Jvm 已使用内存");
        put("mem.jvm.used.String", SizeUtils.getDataSize(used), "Jvm 已使用内存");
        put("mem.jvm.used.rate", rate(used, max), "Jvm 已使用占率");

        put("mem.jvm.free.long", free, "Jvm 剩余内存");
        put("mem.jvm.free.String", SizeUtils.getDataSize(free), "Jvm 剩余内存");
        put("mem.jvm.free.rate", rate(free, max), "Jvm 剩余占率");
    }

}
